package com.icode.dao.impl;

import com.icode.core.model.User;
import com.icode.dao.UserDao;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.Set;

/**
 * User: alexz
 * Date: 15-1-7
 * Time: 下午5:59
 */
@Repository("userDao")
public class UserDaoImpl extends EntityDaoImpl implements UserDao {

    @Override
    public User findUserByUsername(String username) {
        String hql = "from User u where u.username = :username";
        Query query = currentSession().createQuery(hql);
        query.setParameter("username", username);
        return (User) query.uniqueResult();
    }

    @Override
    public Set<String> findAuthorities(String username) {
        String hql = "select u.authorities from User u where u.username=:username";
        Query query = currentSession().createQuery(hql);
        query.setParameter("username", username);
        return (Set<String>) query.uniqueResult();
    }
}
